package com.daisuxia.back.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.daisuxia.back.service.IMmanLoanCollectionOrderService;
import com.daisuxia.back.service.IMmanUserInfoService;
import com.daisuxia.back.utils.BackConstant;
import com.daisuxia.back.vo.jxl.UserReport;
import com.daisuxia.web.pojo.BackUser;
import com.daisuxia.web.pojo.MmanLoanCollectionOrder;

@Controller
@RequestMapping("/mmanUserInfo")
public class MmanUserInfoController extends BaseController{
	private static Logger logger = Logger.getLogger(MmanUserInfoController.class);
	@Autowired
	private IMmanUserInfoService mmanUserInfoService;
	//订单
	@Autowired
	private IMmanLoanCollectionOrderService mmanLoanCollectionOrderService;
    /**
     * 聚信立报告
     * @param request
     * @param response
     * @param model
     * @return
     */
	@RequestMapping("/jxlReport")
	public String getPage(HttpServletRequest request,HttpServletResponse response,Model model){
		String url="mycollectionorder/tapplyJxlRepor";
		try {
			HashMap<String, Object> params = getParametersO(request);
			if(StringUtils.isNotBlank(params.get("id")+"")){
				MmanLoanCollectionOrder mmanLoanCollectionOrderOri = mmanLoanCollectionOrderService.getOrderById(params.get("id").toString());
				BackUser backUser=this.loginAdminUser(request);
				
				if((BackConstant.COLLECTION_ROLE_ID.toString().equals(backUser.getRoleId()) && "2".equals(mmanLoanCollectionOrderOri.getJxlStatus()))|| !BackConstant.COLLECTION_ROLE_ID.toString().equals(backUser.getRoleId())){
					params.put("loanUserId", mmanLoanCollectionOrderOri.getUserId());
					UserReport ur = mmanUserInfoService.findJxlDetail(params);
					model.addAttribute("name", ur.getRealName());
					model.addAttribute("gender", ur.getGender());
					model.addAttribute("idNumber", ur.getIdNumber());
					model.addAttribute("age",ur.getAge());
					model.addAttribute("report", ur.getReport_data().getReport());
					model.addAttribute("check_black_info", ur.getReport_data().getUser_info_check().getCheck_black_info());
					model.addAttribute("ebusiness_expense", ur.getReport_data().getEbusiness_expense());
					model.addAttribute("deliver_address", ur.getReport_data().getDeliver_address());
					model.addAttribute("behavior_check", ur.getReport_data().getBehavior_check());
					model.addAttribute("collection_contact", ur.getReport_data().getCollection_contact());
					model.addAttribute("contact_list", ur.getReport_data().getContact_list());
					model.addAttribute("contact_region", ur.getReport_data().getContact_region());
					model.addAttribute("cell_behavior", ur.getReport_data().getCell_behavior());
					model.addAttribute("main_service", ur.getReport_data().getMain_service());
					model.addAttribute("trip_info", ur.getReport_data().getTrip_info());
					model.addAttribute("check_search_info", ur.getReport_data().getUser_info_check().getCheck_search_info());
					url="mycollectionorder/jxlReport";
				}
			}
			model.addAttribute("params", params);
		} catch (Exception e) {
			logger.error("getMmanLoanCollectionOrder error", e);
		}
		return url;
	}

}
